package com.ooo.ttt.demo.sample1

import android.content.res.Configuration
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.ooo.ttt.demo.databinding.ActivitySurfaceBinding
import com.ooo.ttt.demo.view.MySurfaceView
import com.ooo.ttt.opencvlib.NativeFace
import com.ooo.ttt.opencvlib.camera.CameraLoader
import com.ooo.ttt.opencvlib.camera.Cmare1Loader

class SurfaceActivity : AppCompatActivity() {


    private val activity: SurfaceActivity by lazy {
        this@SurfaceActivity
    }

    val camera: CameraLoader by lazy {
        Cmare1Loader()
    }


    private lateinit var binding: ActivitySurfaceBinding

    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
        camera?.startPreview()

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivitySurfaceBinding.inflate(layoutInflater)
        setContentView(binding.root)


        binding.surface.setCamera(camera)


        binding.surface.setResult(object:MySurfaceView.FaceRectResult{
            override fun onReuslt(nativeFaces: Array<out NativeFace>?) {
                binding.cover.faces = nativeFaces
            }
        })

//        binding.cover.start()


    }

    override fun onDestroy() {
        super.onDestroy()
//        binding.cover.stop()
    }


}